<?php
  if (isset($_REQUEST["n"])) {
    header("Content-type: text/plain; charset=utf-8");
    header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    $num=$_REQUEST["n"];
    if ($num==0) {
      echo '<div style="width: 283px; margin: 0; padding: 54px 0 0 0"><center><img src="/img/news_loading.gif"></center></div>';
    } else {
      echo $num.'#';
      getsortedchanges($num);
    }
	}
//------------------------------------------------------  
  function getsortedchanges($index) {
      $connection=mysql_connect("127.0.0.1","avtovokzal","pipzemkam") or die("Ошибка соединения с сервером");
      $db=mysql_select_db("avtovokzal",$connection) or die("Ошибка при выборе базы данных");
      @mysql_query('set character_set_client="utf8"');
      @mysql_query('set character_set_results="utf8"');
      @mysql_query('set collation_connection="utf8_general_ci"');
      $result=mysql_query("SELECT * FROM `changes` ORDER BY `datetime` DESC LIMIT ".($index-1).",1");
      $row=mysql_fetch_array($result,MYSQL_ASSOC);
      echo '<h3 id="title'.$index.'">'.$row["title"].'</h3><p id="text'.$index.'">'.$row["shorttext"].'</p>';
      echo '<div style="float: left; margin-left: 14px; font-size: 10px; width: 120px"><strong><i>'.substr($row["datetime"],8,2).'.'.substr($row["datetime"],5,2).'.'.substr($row["datetime"],0,4).'</i></strong></div>';
      echo '<a href="#" onclick="showchange('.$row["id"].');" class="more"><i>Подробнее...</i></a>';
		  mysql_close($connection);
	}
?>